<?php

class NoBusinessBase_Controller_Oslc_ServiceProvider extends NoBusinessBase_Controller_Oslc_ActionBase
{
   public function init()
   {
      parent::init();
   }
   
   public function createServiceDescriptorElement($title = '', $description = '')
   {
      $serviceDescriptor = $this->_dom->createElement('rdf:RDF');
      $this->attrAppend($serviceDescriptor, 'xmlns:rdf');
      $this->attrAppend($serviceDescriptor, 'xmlns:dc');
      $this->attrAppend($serviceDescriptor, 'xmlns:oslc');
      
      $serviceProvider = $this->_dom->createElement('oslc:ServiceProvider');
      $this->attrAppend($serviceProvider, 'rdf:about');
      $serviceDescriptor->appendChild($serviceProvider);
      
      if($title != '')
         $serviceProvider->appendChild($this->_dom->createElement('dc:title', $title));
      if($description != '')
         $serviceProvider->appendChild($this->_dom->createElement('dc:description', $description));

      $this->_nextAppendToElement->appendChild($serviceDescriptor);
      $this->_serviceDescriptorElement = $serviceProvider;
      
      $this->_nextAppendToElement = $this->_serviceDescriptorElement;
      
      $this->createServiceElement();
      return $serviceDescriptor;
   }

   public function createServiceElement()
   {
      $sService = $this->_dom->createElement('oslc:service');
      $pChangeRequestsElement = $this->_dom->createElement('oslc:Service');
      $sService->appendChild($pChangeRequestsElement);
      
      $this->_nextAppendToElement->appendChild($sService);
      $this->_nextAppendToElement = $pChangeRequestsElement;
   }
   
   public function createSelectionDialog($params)
   {
      if(!isset($params['url']))
         return;
      
      $this->_helper->valueReplace()->replaceValuesInArray($params);
      
      $pSelectionDialogElement = $this->_dom->createElement('oslc:selectionDialog');
      $DialogElement = $this->_dom->createElement('oslc:Dialog');
      $pSelectionDialogElement->appendChild($DialogElement);
      
      if(isset($params['default'])) {
         $usage = $this->_dom->createElement('oslc:usage');
         $this->attrAppend($usage, 'rdf:resource', 'http://open-services.net/ns/core#default');
         $DialogElement->appendChild($usage);
      }
      if(isset($params['width']))
         $DialogElement->appendChild($this->_dom->createElement('oslc:hintWidth', $params['width']));
      if(isset($params['height']))
         $DialogElement->appendChild($this->_dom->createElement('oslc:hintHeight', $params['height']));
      if(isset($params['title']))
         $DialogElement->appendChild($this->_dom->createElement('dc:title', $params['title']));
      if(isset($params['description']))
         $DialogElement->appendChild($this->_dom->createElement('dc:description', $params['description']));
      if(isset($params['label']))
         $DialogElement->appendChild($this->_dom->createElement('oslc:label', $params['label']));
      
      $dialog = $this->_dom->createElement('oslc:dialog');
      $this->attrAppend($dialog, 'rdf:resource', $params['url']);
      $DialogElement->appendChild($dialog);

      $this->_nextAppendToElement->appendChild($pSelectionDialogElement);
   }
}
